package com.cyj.dream.auth.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.cyj.dream.core.base.SysBaseEntity;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import javax.persistence.Column;
import javax.persistence.Transient;
import java.io.Serializable;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @Description: 系统用户权限表
 * @BelongsProject: dream-DreamChardonnay
 * @BelongsPackage: com.cyj.dream.auth.model
 * @Author: ChenYongJia
 * @CreateTime: 2021-04-02 09:16
 * @Email: chen87647213@163.com
 * @Version: 1.0
 */
@Data
@ToString
@AllArgsConstructor
@NoArgsConstructor
@TableName("sys_permission")
@ApiModel(value = "SysPermission系统用户权限表", description = "sys_permission 系统用户权限表")
public class SysPermission extends SysBaseEntity implements Serializable {

    @ApiModelProperty(value = "权限所属模块")
    @Column(columnDefinition = "varchar(255) COMMENT '权限所属模块'")
    private String sysPermissionModule;

    @ApiModelProperty(value = "权限名称")
    @Column(columnDefinition = "varchar(255) COMMENT '权限名称'")
    private String sysPermissionName;

    @ApiModelProperty(value = "权限资源对象")
    @Column(columnDefinition = "varchar(255) COMMENT '权限资源对象'")
    private String sysPermissionValue;

    @ApiModelProperty(value = "权限资源路径")
    @Column(columnDefinition = "varchar(255) COMMENT '权限资源路径'")
    private String sysPermissionUrl;

    @JsonIgnore
    @Transient
    @TableField(exist = false)
    @ApiModelProperty(value = "角色表关联")
    private Set<SysRole> roleSet = new HashSet<>();

    /**
     * 节点ID，对加载远程数据很重要。
     */
    @Transient
    @TableField(exist = false)
    private Long id;

    /**
     * 显示节点文本。
     */
    @Transient
    @TableField(exist = false)
    private String label;

    @Transient
    @TableField(exist = false)
    private List<SysPermission> children;

    /**
     * 是否选中节点
     */
    @Transient
    @TableField(exist = false)
    private boolean disabled = false;

    /**
     * Instantiates a new sysPermission.
     *
     * @param sysPermissionValue  the sysPermission value
     * @param sysPermissionModule the sysPermission module
     * @param sysPermissionName   the sysPermission name
     */
    public SysPermission(String sysPermissionValue, String sysPermissionModule,
                         String sysPermissionName) {
        super();
        this.sysPermissionValue = sysPermissionValue;
        this.sysPermissionModule = sysPermissionModule;
        this.sysPermissionName = sysPermissionName;
    }

}